package com.example.Cairodio;

import java.util.ArrayList;

import com.example.entities.Comments;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CommentsListAdapter extends BaseAdapter {
	 private static ArrayList<Comments> searchArrayList;
	 private LayoutInflater mInflater;

	 public CommentsListAdapter(Context context, ArrayList<Comments> results){
	  searchArrayList = results;
	  mInflater = LayoutInflater.from(context);
	 }

	 public int getCount() {
	  return searchArrayList.size();
	 }

	 public Object getItem(int position) {
	  return searchArrayList.get(position);
	 }

	 public long getItemId(int position) {
	  return position;
	 }

	 public View getView(int position, View convertView, ViewGroup parent) {
	  ViewHolder holder;
	  if (convertView == null) {
	   convertView = mInflater.inflate(R.layout.comment_item, null);
	   holder = new ViewHolder();
	   holder.txtComment = (TextView) convertView.findViewById(R.id.commentText);
	   holder.txtDate = (TextView) convertView.findViewById(R.id.dateText);

	   convertView.setTag(holder);
	  } else {
	   holder = (ViewHolder) convertView.getTag();
	  }
	  
	  holder.txtComment.setText(searchArrayList.get(position).getComment());
	  holder.txtDate.setText(searchArrayList.get(position).getDate());

	  return convertView;
	 }

	 static class ViewHolder {
	  TextView txtComment;
	  TextView txtDate;
	 }
	}


